package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class JDBCDemo3 {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root");
        System.out.println("与数据库建立连接成功");

        // 创建Statement语句对象
        Statement statement = connection.createStatement();
        String sql = "UPDATE user SET password='666666',age=22,nickname='沟沟' WHERE username='张麒'";
        int count = statement.executeUpdate(sql);// 返回值表示受影响的行数
        System.out.println(count > 0 ? "修改成功" : "修改失败");
        connection.close();
    }
}
